package com.quwan.manager.controller;

import com.quwan.common.BaseController;
import com.quwan.common.exception.ExpCode;
import com.quwan.common.result.ApiResult;
import com.quwan.common.result.PageResult;
import com.quwan.entity.TCircle;
import com.quwan.manager.controller.dto.CircleDto;
import com.quwan.manager.service.ICircleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author laozhang
 * @date 2022/3/17
 */
@Api(tags = "后台圈子管理接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("mgr/circle")
public class CircleController extends BaseController {

    private final ICircleService circleService;


    @ApiOperation(value = "圈子列表分页",notes = "<span style=\"color:red\">注意参数是否必填</span>",httpMethod = "POST")
    @PostMapping("circleListPage")
    public ApiResult<PageResult<CircleDto>> CircleListPage(@RequestParam(defaultValue = "1") int page,
                                                           @RequestParam(defaultValue = "10") int size,
                                                           @ApiParam(value="用户昵称",required = false) @RequestParam(required = false) String nickName,
                                                           @ApiParam(value="圈子名称id",required = false) @RequestParam(required = false) Long circleNameId,
                                                           @ApiParam(value="圈子类型id",required = false) @RequestParam(required = false) Long circleTypeId,
                                                           @ApiParam(value="开始时间（yyyy-MM-hh）",required = false) @RequestParam(required = false) String beginTime,
                                                           @ApiParam(value="结束时间（yyyy-MM-hh）",required = false) @RequestParam(required = false) String endTime) {
        PageResult<CircleDto> res = circleService.getCircleListPage(page, size, nickName, circleTypeId, circleNameId, beginTime, endTime);
        return ApiResult.success(res);
    }

    @PostMapping("delCircle")
    @ApiOperation("删除圈子——圈子下评论也删除")
    public ApiResult delCircle(@RequestParam(value = "id") String id){
        boolean success = circleService.delCircle(Long.valueOf(id));
        if (success)
            return ApiResult.successMsg();
        else
            return ApiResult.failed();
    }
   

}
